package com.mqb.n3;

import lombok.extern.slf4j.Slf4j;

import static com.mqb.n2.util.Sleeper.sleep;

/**
 * @author mqb
 * @date 2021/4/16 22:24
 */
@Slf4j(topic = "c.TestJoin")
public class TestJoin {
    static int r1, r2, r3 = 0;

    public static void main(String[] args) throws InterruptedException {
        test2();
    }

    private static void test2() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            sleep(2);
            r1 = 10;
        }, "t1");

        Thread t2 = new Thread(() -> {
            sleep(1);
            r2 = 20;
        }, "t2");

        t1.start();
        t2.start();

        long start = System.currentTimeMillis();
        log.debug("join begin");
        t1.join();
        log.debug("t1 join end");
        t2.join();
        log.debug("t2 join end");
        long end = System.currentTimeMillis();
        log.debug("r1: {}, r2: {}, cost: {}", r1, r2, end - start); // r1: 10, r2: 20, cost: 2015
    }
}
